{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "img = cv2.imread('qqicon.jfif')\n",
    "gray = cv2.cvtColor(img,6)\n",
    "_,binary = cv2.threshold(gray,150,255,8)\n",
    "cv2.imshow('img',img)\n",
    "cv2.imshow('gray',gray)\n",
    "cv2.imshow('binary',binary)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "cap = cv2.VideoCapture(0) #调用本机摄像头\n",
    "while True:\n",
    "    ok,img = cap.read()\n",
    "    gray = cv2.cvtColor(img,6)\n",
    "    _,binary = cv2.threshold(gray,120,255,0)\n",
    "    cv2.imshow('img',img)\n",
    "    cv2.imshow('binary',binary)\n",
    "    if cv2.waitKey(1) > 0:\n",
    "        break\n",
    "cv2.destroyAllWindows()\n",
    "cap.release()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2helper as cv2h\n",
    "import cv2\n",
    "cap = cv2.VideoCapture(0) #调用本机摄像头\n",
    "while True:\n",
    "    ok,img = cap.read()\n",
    "    if ok:\n",
    "        binary = cv2h.img01(img,6,120,255,8)\n",
    "        cv2.imshow('binary',binary)\n",
    "        if cv2.waitKey(1) > 0:\n",
    "            break\n",
    "cv2.destroyAllWindows()\n",
    "cap.release()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 很明显，这里往下是今天的内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import cv2helper as cv2h\n",
    "import cv2\n",
    "\n",
    "#创建膨胀核\n",
    "kernel = np.ones((3,3))\n",
    "img = cv2.imread('wordbig.png')\n",
    "\n",
    "#扩大和缩小边缘\n",
    "binary = cv2h.img01(img,6,120,255,8)\n",
    "dilate = cv2.dilate(binary,kernel,iterations=4) #扩大（膨胀）\n",
    "erode = cv2.erode(binary,kernel,iterations=2) #缩小（腐蚀）\n",
    "\n",
    "cv2.imshow('gray',gray)\n",
    "cv2.imshow('dilate',dilate)\n",
    "cv2.imshow('erode',erode)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
